//
// File:	Event.hpp
// Author:	Thomas TISSOT-DUPONT
// Login:	<thomas.tissotdupont@free.fr>
//
// Created:	16/04/2010 at 16:18:23
// Purpose:	
//
#ifndef EVENT_HPP
#define EVENT_HPP

#include <boost/function.hpp>
#include <boost/bind.hpp>
#include "IEventManager.hpp"

//------------------------------------------------------------------
// Quick and Dirty Events
//------------------------------------------------------------------
#define emit
#define events
#define CONNECT_METHOD_TEMPLATE(pA, eA, pB, fB, args)		if (pA)																											\
															{																												\
																IEventManager::EventConnection con = (pA)->eA.connect(boost::bind(fB, pB args));							\
																GlobalVariables::EventManager::Get().Connect((void *)(pA), (void *)&(pA)->eA, (void *)(pB), (#fB), con);	\
															}
#define CONNECT_METHOD_0(pA, eA, pB, fB)					CONNECT_METHOD_TEMPLATE(pA, eA, pB, fB, _args0)
#define CONNECT_METHOD_1(pA, eA, pB, fB)					CONNECT_METHOD_TEMPLATE(pA, eA, pB, fB, _args1)
#define CONNECT_METHOD_2(pA, eA, pB, fB)					CONNECT_METHOD_TEMPLATE(pA, eA, pB, fB, _args2)
#define CONNECT_METHOD_3(pA, eA, pB, fB)					CONNECT_METHOD_TEMPLATE(pA, eA, pB, fB, _args3)
#define CONNECT_METHOD_4(pA, eA, pB, fB)					CONNECT_METHOD_TEMPLATE(pA, eA, pB, fB, _args4)
#define CONNECT_METHOD_5(pA, eA, pB, fB)					CONNECT_METHOD_TEMPLATE(pA, eA, pB, fB, _args5)
#define CONNECT_METHOD_6(pA, eA, pB, fB)					CONNECT_METHOD_TEMPLATE(pA, eA, pB, fB, _args6)
#define CONNECT_METHOD_7(pA, eA, pB, fB)					CONNECT_METHOD_TEMPLATE(pA, eA, pB, fB, _args7)
#define CONNECT_METHOD_8(pA, eA, pB, fB)					CONNECT_METHOD_TEMPLATE(pA, eA, pB, fB, _args8)
#define CONNECT_METHOD_9(pA, eA, pB, fB)					CONNECT_METHOD_TEMPLATE(pA, eA, pB, fB, _args9)
#define DISCONNECT_METHOD(pA, eA, pB, fB)					if (pA) GlobalVariables::EventManager::Get().Disconnect((void *)(pA), (void *)&(pA)->eA, (void *)(pB), #fB)

template <typename T>
struct Event : public boost::signals2::signal<T>
{
};

//------------------------------------------------------------------
// Event Args
//------------------------------------------------------------------
#define _args0
#define _args1										, _1
#define _args2										_args1, _2
#define _args3										_args2, _3
#define _args4										_args3, _4
#define _args5										_args4, _5
#define _args6										_args5, _6
#define _args7										_args6, _7
#define _args8										_args7, _8
#define _args9										_args8, _9

#endif //!EVENT_HPP
